#!/bin/sh

username="your_qq"
password="your_qq_password"

sid=`curl -c qq.cookie -d "qq=$username&pwd=$password&q_from=mblog&modifySKey=0&loginType=3&aid=nLoginHandle" 'http://pt5.3g.qq.com/microblogLogin?&amp;sid=zEEpfFLlnxmXmdFJoYat3g==' 2>/dev/null |grep sid=|head -n 1|sed 's/.*sid=\(.*\)&amp;.*/\1/g'`
post_url=`curl -b qq.cookie "http://ti.3g.qq.com/g/s?aid=h&sid=$sid" 2>/dev/null |grep '<anchor>广播<go href='|sed 's/.*<anchor>广播<go href="\(.*\)" method="post">.*/\1/g'|awk -F\" '{print $1}'|sed 's/amp;//g'`

msg_encoded=$(echo "$1" | sed -e 's/%/%25/g' -e 's/ /%20/g' -e 's/!/%21/g' -e 's/"/%22/g' -e 's/#/%23/g' -e 's/\$/%24/g' -e 's/\&/%26/g' -e 's/'\''/%27/g' -e 's/(/%28/g' -e 's/)/%29/g' -e 's/\*/%2a/g' -e 's/+/%2b/g' -e 's/,/%2c/g' -e 's/-/%2d/g' -e 's/\./%2e/g' -e 's/\//%2f/g' -e 's/:/%3a/g' -e 's/;/%3b/g' -e 's//%3e/g' -e 's/?/%3f/g' -e 's/@/%40/g' -e 's/\[/%5b/g' -e 's/\\/%5c/g' -e 's/\]/%5d/g' -e 's/\^/%5e/g' -e 's/_/%5f/g' -e 's/`/%60/g' -e 's/{/%7b/g' -e 's/|/%7c/g' -e 's/}/%7d/g' -e 's/~/%7e/g')

url="http://ti.3g.qq.com$post_url&msg=$msg_encoded&ac=51"
#echo $url
res=`curl -b qq.cookie "$url" 2>/dev/null|grep -c '消息发表成功！'`
if [ "$res" -eq 0 ]; then
    echo -e "\033[1;31m发表失败!\033[0m"
    exit 1;
else
    echo -e "\033[1;32m发表成功!\033[0m"
fi
